<%@ page import="java.sql.*" %>
<%--
  Created by IntelliJ IDEA.
  User: 17126
  Date: 2022/4/29
  Time: 9:04
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>数据库链接</title>
</head>
<body>
<%
    try {
        Class.forName("com.mysql.cj.jdbc.Driver");
        String url = "jdbc:mysql://localhost:3306/user";
        String username = "root";
        String password = "root";

        Connection conn = DriverManager.getConnection(url, username, password);
        if (conn != null){
            out.print("数据库连接成功！");
            conn.close();
        }
        else
            out.print("数据库连接失败！");
    } catch (ClassNotFoundException | SQLException e) {
        e.printStackTrace();
    }
%>
</body>
</html>
